<!DOCTYPE html>

<html lang="en" class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Edit Storage</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script type="text/javascript" th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form" id="fm" enctype="multipart/form-data">
                <div class="layui-form-item" style="display: none">
                    <label for="managerNo" class="layui-form-label">
                        <span class="x-red">*</span>管理员编号
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="managerNo" name="managerNo"
                               required="" lay-verify="managerNo" autocomplete="off"
                               class="layui-input" th:value="${manager.managerNo}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="managerName" class="layui-form-label">
                        <span class="x-red">*</span>管理员姓名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="managerName" name="managerName" required=""
                               lay-verify="managerName" autocomplete="off" class="layui-input"
                                th:value="${manager.managerName}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>将会成为您唯一的登入名
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="managerPassword" class="layui-form-label"> <span
                            class="x-red">*</span>密&emsp;&emsp;码
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="managerPassword" name="managerPassword"
                               required="" lay-verify="managerPassword" autocomplete="off"
                               class="layui-input" th:value="${manager.managerPassword}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">6到16个字符</div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label" id="sexRadio">性&emsp;&emsp;别</label>
                    <div class="layui-input-block">
                        <input class="radio" type="radio" name="managerSex" value="男" title="男"
                               checked>
                        <input class="radio" type="radio" name="managerSex" value="女" title="女">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label for="managerPhone" class="layui-form-label"> <span
                            class="x-red">*</span>联系方式
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="managerPhone" name="managerPhone" required=""
                               lay-verify="phone" autocomplete="off" class="layui-input"
                               th:value="${manager.managerPhone}">
                    </div>

                </div>

                <div class="layui-form-item">
                    <label for="managerEmail" class="layui-form-label"> <span
                            class="x-red">*</span>管理员邮箱
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="managerEmail" name="managerEmail"
                               lay-verify="email" class="layui-input" th:value="${manager.managerEmail}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="managerHiredate" class="layui-form-label">管理员雇佣时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="managerHiredate"
                               placeholder="yyyy-MM-dd HH:mm:ss" th:value="${manager.managerHiredate}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button id="L_repass" class="layui-btn" lay-filter="edit"
                            lay-submit="">修改</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    layui.use([ 'form', 'layer', 'jquery', 'upload' ], function() {
        $ = layui.jquery;
        var form = layui.form, layer = layui.layer, upload = layui.upload;

        //自定义验证规则
        form
            .verify({
                managerName : function(value) {
                    if (value.length < 5) {
                        return '昵称至少得5个字符啊';
                    }
                },
                managerPassword : [ /(.+){6,12}$/, '密码必须6到12位' ],
                reManagerPassword : function(value) {
                    if ($('#managerPassword').val() !== $(
                        '#reManagerPassword').val()) {
                        return '两次密码不一致';
                    }
                }
            });

        //监听提交
        form.on('submit(edit)', function(data) {
            console.log(data.field)
            $.ajax({
                url : "/manager/edit",
                method : 'post',
                data : data.field,
                dataType : 'JSON',
                success : function(res) {
                    if (res.code === 0) {
                        //弹出提示，并在1秒后进行跳转
                        layer.alert("修改成功", {
                            icon : 6
                        }, function() {
                            //关闭当前frame
                            xadmin.close();

                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                            return false;
                        });
                    } else {
                        layer.msg("修改失败:" + res.msg);
                        return false;
                    }
                }
            });
            return false;
        });
    })
</script>
</body>
</html>

